package br.usjt.lab.hirose;

import java.util.Queue;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.LinkedList;

import javax.swing.JFrame;

public class testeFloodFill extends TelaPrincipal{

	private static final long serialVersionUID = 1L;
	private BufferedImage img;

	public testeFloodFill(Graphics2D g) {
		img = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB);
		System.out.println(img.getMinTileX());
	}

	public void paintComponents(Graphics g){
		super.paintComponents(g);
	}
	public static void fillArea(int x, int y, int original, int fill, BufferedImage picture) {
		if (x != 0)
			x--;
		if (y != 0)
			y--;
		Queue<Point> queue = new LinkedList<Point>();
		if (picture.getRGB(y, x) != original) {
			return;
		}
		queue.add(new Point(x, y));

		while (!queue.isEmpty()) {
			Point p = queue.remove();

			if (picture.getRGB(p.y, p.x) == original &&(p.y > 0 && p.x >0)) {
				picture.setRGB(p.y, p.x, 254);
				System.out.println(picture);
				queue.add(new Point(p.x - 1, p.y));
				queue.add(new Point(p.x + 1, p.y));
				queue.add(new Point(p.x, p.y - 1));
				queue.add(new Point(p.x, p.y + 1));
			}
			System.out.println(p);
		}

	}
	
	@Override
	public void paint(Graphics g) {
		fillArea(2, 2, img.getRGB(2, 2), 200, img);
		g.drawImage(img, 10, 10, null);
	}

	GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 
	GraphicsDevice gs = ge.getDefaultScreenDevice(); 
	GraphicsConfiguration gc = gs.getDefaultConfiguration();
	 
	BufferedImage dbImage = gc.createCompatibleImage(500, 500, Transparency.TRANSLUCENT);	 
	 
	public static void main(String args[]) {
		JFrame f = new JFrame("Ex 1");
		f.setBounds(10, 10, 256, 256);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.add(painel);
		f.setVisible(true);
	}
}
